<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('选择订单产品出库')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>主题：</p>
                                <input type="text" name="orderName"/>
                            </li>
                            <li>
                                <p>付款状态：</p>
                                <select name="orderStatus" th:with="type=${@dict.getType('order_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var orderStatusDatas = [[${@dict.getType('order_status')}]];
        var orderOutStatusDatas = [[${@dict.getType('order_out_status')}]];
        var prefix = ctx + "crm/order";
		var prefixOrderProduct =  ctx + "crm/orderProduct";

        $(function() {
            var options = {
                url: prefix + "/listSelectOrderProductOut",
                queryParams: queryParams,
		        showSearch: false,
		        showRefresh: false,
		        showToggle: false,
		        showColumns: false,
		        clickToSelect: true,
                modalName: "成交订单",
                columns: [{
                	radio: true
                },
                {
                    field : 'orderId', 
                    title : '订单ID',
                    visible: false
                },
                {
                    field : 'orderCode', 
                    title : '订单编码',
                    visible:false
                },
                {
                    field : 'contractId', 
                    title : '合同ID',
		            sortable: true,
                    visible:false
                },
                {
                    field : 'customerId', 
                    title : '客户id',
                    visible:false,
		            sortable: true
                },
                {
                    field : 'orderName', 
                    title : '主题',
		            sortable: true
                },
                {
                    field : 'orderDate', 
                    title : '成交/签约时间',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(value)){
                    		return value.substring(0,10);
                    	}
                     }
                },
                {
                	field : 'customer.customerName', 
                    title : '成交客户',
		            sortable: true
                },
                {
                    field : 'totalPrice', 
                    title : '成交总额',
		            sortable: true
                },
                {
                    field : 'costPrice', 
                    title : '总成本',
		            sortable: true
                },
                {
                    field : 'aaa', 
                    title : '利润',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(row.totalPrice)&&$.common.isNotEmpty(row.costPrice)){
                    		return row.totalPrice-row.costPrice;
                    	}
                     }
                },
                {
                    field : 'orderStatus', 
                    title : '付款状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'orderOutStatus', 
                    title : '出库状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderOutStatusDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'validStart', 
                    title : '有效期开始时间',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(value)){
                    		return value.substring(0,10);
                    	}
                     }
                },
                {
                    field : 'validEnd', 
                    title : '有效期结束时间',
		            sortable: true,
                    formatter: function(value, row, index) {
                    	if($.common.isNotEmpty(value)){
                    		return value.substring(0,10);
                    	}
                     }
                },
                {
                    field : 'createBy', 
                    title : '录入人',
		            sortable: true
                },
                {
                    field : 'createTime', 
                    title : '录入时间',
		            sortable: true
                }]
            };
            $.table.init(options);
        });
		
		function queryParams(params) {
			var search = $.table.queryParams(params);
			return search;
		}
        
        /* 选择出库订单 */
		function submitHandler() {
			var id = $.table.selectFirstColumns();
			var name = $.table.selectColumns("orderName");
			var totalPrice = $.table.selectColumns("totalPrice");
			if (id.length == 0) {
       			$.modal.alertWarning("请选择一条记录");
       			return;
       		}
			$.modal.close();
			parent.$('#orderId').val('');
			parent.$('#orderName').val('');
			parent.$('#orderId').val(id);
			parent.$('#orderName').val(name);			
		}
    </script>
</body>
</html>